/*
 * Questa classe rappresenta l'intera rete fisica
 */

using namespace std;

class PhysicalNet
{
    private:
    vector< vector<PhysicalLink> > matrice;

	public:
	PhysicalNet();
	PhysicalNet(int n);
	bool addLink(int i, int j, string policy, int bandwidth, int latency, bool state);
	string getPolicy(int i, int j);
	int getBandwidth(int i, int j);
	int getBandwidthUsage(int i, int j);
	bool addBandwidthUsage(int i, int j, int bandwidth);
	int getLatency(int i, int j);
	bool getState(int i, int j);
	bool resize(int n);
	bool init();
	int getSize();
	bool reset();
	bool killLinksWithAS(int number);
};

PhysicalNet::PhysicalNet()
{;}

PhysicalNet::PhysicalNet(int n)
{
    matrice.resize(n);
    for (int i=0; i<n; i++) matrice[i].resize(n);

    for (int i=0; i<n; i++)
        for (int j=0; j<n; j++)
            matrice[i][j] = PhysicalLink(i, j, "", 0, 0, false);
}

bool PhysicalNet::addLink(int i, int j, string policy, int bandwidth, int latency, bool state)
{
    matrice[i][j] = PhysicalLink(i, j, policy, bandwidth, latency, state);
}

string PhysicalNet::getPolicy(int i, int j)
{
    return matrice[i][j].getPolicy();
}

int PhysicalNet::getBandwidth(int i, int j)
{
    return matrice[i][j].getBandwidth();
}

int PhysicalNet::getBandwidthUsage(int i, int j)
{
    return matrice[i][j].getBandwidthUsage();
}

bool PhysicalNet::addBandwidthUsage(int i, int j, int value)
{
    matrice[i][j].addBandwidthUsage(value);
}

int PhysicalNet::getLatency(int i, int j)
{
    return matrice[i][j].getLatency();
}

bool PhysicalNet::getState(int i, int j)
{
    return matrice[i][j].getState();
}

bool PhysicalNet::resize(int n)
{
    matrice.resize(n);
    for(int i = 0;i < n;++i) matrice[i].resize(n);
}

bool PhysicalNet::init()
{
    int n = matrice.size();
    for (int i=0; i<n; i++)
        for (int j=0; j<n; j++)
            matrice[i][j] = PhysicalLink(i, j, "", 0, 0, false);
}

int PhysicalNet::getSize()
{
    return matrice.size();
}

bool PhysicalNet::killLinksWithAS(int number)
{
    int n = matrice.size();
    for (int i=0; i<n; i++)
        for (int j=0; j<n; j++)
            if ((matrice[i][j].getASOrigin() == number) || (matrice[i][j].getASDestination() == number))
            {
                matrice[i][j].setState(false);
                //matrice[i][j].resetBandwidthUsage();
            }
}

bool PhysicalNet::reset()
{
    int n = matrice.size();
    for (int i=0; i<n; i++)
        for (int j=0; j<n; j++)
            matrice[i][j].resetBandwidthUsage();
}
